{extend name="default/base/base_member" /}
{block name="member_main"}

<div class="eject_con">
    <div class="adds">
        <div class="alert alert-success">
            <ul>
                <li>{$Think.lang.address_description}</li>
            </ul>
        </div>
        <div id="warning"></div>
        <form method="post" action="{:url('Memberaddress/chain_add')}" id="address_form" target="_parent">
            <input type="hidden" name="address_id" value="{$address_info.address_id|default=''}" />
            <dl>
                <dt><i class="required">*</i>{$Think.lang.region_selection}：</dt>
                <dd>{$Think.lang.find}
                    <span>
                        <input type="hidden" value="{$address_info.city_id|default=''}" name="city_id" id="_area_2">
                        <input type="hidden" value="{$address_info.area_id|default=''}" name="area_id" id="_area">
                        <input type="hidden" name="area_info" id="region" value="{$address_info.area_info|default=''}"/>
                       
                    </span>{$Think.lang.scope_since_mention_service}。
                </dd>
            </dl>
            <div class="dsmc-chain">
                <div id="zt_address"></div>
                <div class="chain-map" id="container" style="height:250px;width:250px"></div>
            </div>

            <dl>
                <dt><i class="required">*</i>{$Think.lang.name_of_consignee}{$Think.lang.ds_colon}</dt>
                <dd>
                    <input type="text" class="text w100" name="true_name" value="{$address_info.address_realname|default=''}"/>
                    <p class="hint"></p>
                </dd>
            </dl>
            <dl>
                <dt>{$Think.lang.consignee_number}{$Think.lang.ds_colon}</dt>
                <dd>
                    <input type="text" class="text w200" name="tel_phone" value="{$address_info.address_tel_phone|default=''}"/>
                    <p class="hint">{$Think.lang.area_code_extension}</p>
                </dd>
            </dl>
            <dl>
                <dt><i class="required">*</i>{$Think.lang.mobile_phone}{$Think.lang.ds_colon}</dt>
                <dd>
                    <input type="text" class="text w200" name="mob_phone" value="{$address_info.address_mob_phone|default=''}"/>
                </dd>
            </dl>
            <div class="bottom">
                <input type="submit" class="submit" value="{$Think.lang.ds_common_button_save}" />
                <a class="dsm-btn ml5" href="javascript:DialogManager.close('daisou');">{$Think.lang.ds_cancel}</a> 
            </div>
        </form>
    </div>
</div>

<script src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js"></script>
<script type="text/javascript" src="//api.map.baidu.com/api?v=3.0&ak={$Think.config.ds_config.baidu_ak}"></script>
<script type="text/javascript">
    var map
    $(document).ready(function () {
        map = new BMap.Map("container");
        $("#region").ds_region();
        $('#address_form').validate({
            submitHandler: function (form) {
                if ($('input[type="radio"]:checked').size() == 1) {
                    ds_ajaxpost('address_form');
                }
            },
            rules: {
                true_name: {
                    required: true
                },
                tel_phone: {
                    required: check_phone,
                    minlength: 6,
                    maxlength: 20
                },
                mob_phone: {
                    required: check_phone,
                    minlength: 11,
                    maxlength: 11,
                    digits: true
                }
            },
            messages: {
                true_name: {
                    required: '{$Think.lang.please_fill_name_consignee}'
                },
                tel_phone: {
                    required: '{$Think.lang.fill_least_one_phone}',
                    minlength: '{$Think.lang.please_correct_fill_phone_number}',
                    maxlength: '{$Think.lang.please_correct_fill_phone_number}'
                },
                mob_phone: {
                    required: '{$Think.lang.fill_least_one_phone}',
                    minlength: '{$Think.lang.please_fill_phone_number_correctly}',
                    maxlength: '{$Think.lang.please_fill_phone_number_correctly}',
                    digits: '{$Think.lang.please_fill_phone_number_correctly}'
                }
            },
            groups: {
                phone: 'tel_phone mob_phone'
            }
        });
        $('#address_form').on('change', 'select', function () {
        area_id = $('#address_form').find('select').last().val();
        if (area_id != '{$Think.lang.ds_please_choose}') {
            map.centerAndZoom($('#address_form').find('select').first().find('option:selected').text(), 15);
            $('#zt_address').load("{$Think.HOME_SITE_URL}/memberaddress/chain_list.html?chain_id={$address_info.chain_id|default=''}&area_id=" + area_id);
        }
        });
        {if intval($Request.param.address_id)}
        $('#zt_address').load("{$Think.HOME_SITE_URL}/memberaddress/chain_list.html?chain_id={$address_info.chain_id|default=''}&area_id={$address_info.area_id|default=''}");
        {/if}
    });
    function check_phone() {
        return ($('input[name="tel_phone"]').val() == '' && $('input[name="mob_phone"]').val() == '');
    }
</script>


{/block}